package com.example.eurekaclient.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.logging.Logger;

/**
 * @Auther: zyb
 * @Date: 2018/11/2 16:28
 * @Description:
 */
@RestController
public class TestController {

    private final Logger logger = Logger.getLogger(String.valueOf(getClass()));

    @Autowired(required = false)
    private DiscoveryClient discoveryClient;

    @GetMapping("/index")
    public String index() {
        StringBuffer stringBuffer = new StringBuffer();
        //TODO 获取服务列表
        List<String> services = discoveryClient.getServices();
        if (services != null) {
            for (String service : services) {
                stringBuffer.append(service).append(",");
            }
        }
        logger.info(stringBuffer.toString());
        return stringBuffer.toString();
    }

    @GetMapping("/getUserName")
    public String getUserName(@RequestParam String name) {
        return name;
    }

    @GetMapping("/getUserInfo")
    public String getUserInfo(@RequestParam String name, @RequestParam String password) {
        return name + "-" + password;
    }

    @PostMapping("/putUserName")
    public String putUserName(@RequestParam String name, @RequestParam String password){
        return name + "-" + password;
    }

}
